<div id="formDiv"></div>
<script type="text/html" id="warehouseProductionOrderformContent">
    <form lay-filter="warehouseProductionOrderForm" id="warehouseProductionOrderForm" class="layui-form open-form">
        <div class="open-model">
            <div class="open-auto">

                <table class="layui-table" id="lookDataForm" lay-filter="lookDataForm">
                    <thead>
                    <tr>

                        <th lay-data="{field:'customerName', width:150, sort: true, fixed: 'left'}">客户名称</th>
                        <th lay-data="{field:'billPrice', width:150, sort: true, fixed: 'left'}">合计金额
                        </th>
                        <th lay-data="{field:'totalDetailPrice', width:150, sort: true, fixed: 'left'}">预计金额
                        </th>
                        <th lay-data="{field:'billStatusDesc', width:150, sort: true, fixed: 'left'}">状态</th>
                        <th lay-data="{field:'billType', width:150, sort: true, fixed: 'left'}">结算方式</th>
                        <th lay-data="{field:'billPeriod', width:150, sort: true, fixed: 'left'}">日期</th>

                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <td>
                            <input type="text" class="layui-input" id="customerName" disabled name="customerName"/>
                        </td>
                        <td>
                            <input type="text" class="layui-input" id="billPrice" disabled name="billPrice"/>
                        </td>
                        <td>
                            <input type="text" class="layui-input" id="totalDetailPrice" disabled name="totalDetailPrice"/>
                        </td>
                        <td>
                            <input class="layui-input adv-disable" id="billStatusDesc" disabled name="billStatusDesc"/>
                        </td>
                        <td>
                            <input type="text" class="layui-input" id="billType" disabled name="billType"/>
                        </td>
                        <td>
                            <input class="layui-input adv-disable" id="billPeriod" disabled name="billPeriod"/>
                            <!--              <input type="text" class="layui-input adv-disable" id="creatorName" disabled name="creatorName" />-->
                        </td>


                    </tr>
                    </tbody>
                </table>

                <div class="layui-form-item tableContent">
                    <table class="layui-table" id="purchasePlanFormTable" lay-filter="purchasePlanFormTable"></table>
                </div>

                <div class="layui-form-item text-right">
                    <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">关闭</button>
                </div>
            </div>
        </div>
    </form>
</script>
<script>
    layui.use(["layer", "form", "table", "admin", "laydate", "upload", "laytpl"], async function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        let laydate = layui.laydate;
        let laytpl = layui.laytpl;
        const nowData = {...parentData};
        let data = nowData?.data;
        console.log(nowData)

        try {
            if (!data.status) {
                nowData.status = 0
            } else {
                nowData.status = data.status
            }
        } catch (e) {
            nowData.status = 0
        }

        laytpl(warehouseProductionOrderformContent.innerHTML).render({...nowData}, function (html) {
            $("#formDiv").after(html);
        });
        // 直接填充数据
        $("#customerName").val(nowData.data.customerName || "无");
        $("#billPrice").val(nowData.data.billPrice || "无");
        $("#totalDetailPrice").val(nowData.data.totalDetailPrice || "无");
        $("#billStatusDesc").val(nowData.data.billStatusDesc || "无");
        $("#billPeriod").val(nowData.data.billPeriod || "无");
        $("#billType").val(nowData.data.billType==='1'?"月结":"手动");
        // 初始化日期选择
        laydate.render({
            elem: "#deliveryTime",
            type: "datetime"
        });




        // if (nowData.eventName === "detail") {
        //     admin.setFormDisable("#warehouseProductionOrderForm", true);
        // }

        const tableVal = table.render({
            elem: "#purchasePlanFormTable",
            page: false,
            limit: 999999,
            //   height: 400,
            data: [],
            cols: [
                [
                    {type: "numbers", title: "序号"},
                    {field: "id", align: "center", title: "id"},
                    {field: "billType", align: "center", title: "账单类别",templet: function (d) {
                            if (d.billType == 1) {
                                return "月结";
                            } else if (d.billType == 2) {
                                return "手动";
                            }else {
                                return "无"
                            }
                        }},
                    {field: "transferType", align: "center", title: "账单类型",templet: function (d) {
                            if (d.transferType == 1) {
                                return "托管";
                            } else if (d.transferType == 2) {
                                return "过户";
                            }else if (d.transferType == 3) {
                                return "加工";
                            }else {
                                return "无"
                            }
                        }},
                    {field: "billPrice", align: "center", title: "金额"},
                    { field: "billPeriod", align: "center", title: "账单周期" },
                    { field: "startDate", align: "center", title: "计费开始日期" },
                    { field: "endDate", align: "center", title: "计费结束日期" },

                    // {
                    //     field: "processingDrawing",
                    //     align: "center",
                    //     title: "加工图纸",
                    //     templet: admin.setTableUpload("processingDrawing", nowData.eventName == "detail")
                    // },
                    {
                        field: "remark",
                        align: "center",
                        title: "加工备注",
                        templet: function (d) {
                            return d.remark || "无";
                        }
                    }
                ]
            ],
        });

        tableVal.reload({
            data: nowData.data.warehouseBillDetailList
            ,
        })

        table.on("tool(purchasePlanFormTable)", function (obj) {
            var d = obj.data; // 获取当前行的数据
            var layEvent = obj.event; // 获取事件名（edit 或 del）
            if (obj.tr) {
                obj.tr.on("click", function (e) {
                    e.preventDefault(); // 防止默认行为
                });
            }
        });
    });
</script>

<style>
    #warehouseProductionOrderForm .layui-form-label {
        width: 125px;
    }

    #warehouseProductionOrderForm .layui-input-block {
        margin-left: 155px;
    }

    #warehouseProductionOrderForm .layui-form-item .layui-inline {
        /* margin-bottom: 5px; */
        margin-right: 0px;
    }
</style>
